package com.maxmlr.music.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.maxmlr.music.common.param.DictTypeParam;
import com.maxmlr.music.system.entity.Dict;
import com.maxmlr.music.system.dao.DictMapper;
import com.maxmlr.music.system.service.DictService;
import com.maxmlr.music.common.base.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author max
 * @version 1.0
 * @ClassName DictServiceImpl
 * @Description 字典表  服务实现类
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@Service
public class DictServiceImpl extends BaseServiceImpl<DictMapper, Dict> implements DictService {

    @Override
    public List<DictTypeParam> getTypes() {
        return Optional.ofNullable(list(Wrappers.<Dict>lambdaQuery()
                .select(Dict::getType, Dict::getDescription).groupBy(Dict::getType, Dict::getDescription)))
                .orElse(Lists.newArrayList())
                .stream()
                .map(p -> new DictTypeParam(p.getType(), p.getDescription()))
                .collect(Collectors.toList());
    }
}
